﻿
using System.Collections.ObjectModel;
using System.Linq;

using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    [Filter("霍夫变换S", FilterType.Algorithm)]
    public class AlgorithmHoughLines : FilterBase
    {
        /// <summary>
        /// 累加器距离
        /// </summary>
        [InputParameter("距离")]
        public double Rho { get; set; }
        /// <summary>
        /// 累加器以弧度为单位的
        /// </summary>
        [InputParameter("角度")]
        public double Theta { get; set; }
        /// <summary>
        /// 累加器阈值参数
        /// </summary>
        [InputParameter("阈值参数")] 
        public int Threadhod { get; set; }
        /// <summary>
        /// 对于多尺度霍夫变换，它是距离分辨率的除数
        /// </summary>
        [InputParameter("多尺度除数",ParameterType.Optional)]
        public double Srn { get; set; }
        /// <summary>
        /// 对于多尺度霍夫变换，它是距离分辨率的角度
        /// </summary>
        [InputParameter("多尺度角度", ParameterType.Optional)] 
        public double Stn { get; set; }
        /// <summary>
        /// The output vector of lines. Each line is represented by a two-element vector
        //     (rho, theta) . rho is the distance from the coordinate origin (0,0) (top-left
        //     corner of the image) and theta is the line rotation angle in radians
        /// </summary>
        [OutputParameter("输出向量")]
        public ObservableCollection<CVLineSegmentPolar> LineSegmentPolars { get; set; } = new ObservableCollection<CVLineSegmentPolar>();
        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterInfos, FilterBase preFilterBase)
        {
           var polor=  Cv2.HoughLines(mat, Rho, Theta, Threadhod, Srn, Stn);
            if (polor!=null)
            {
                LineSegmentPolars = new ObservableCollection<CVLineSegmentPolar>(polor.Select(p => (CVLineSegmentPolar)p));
            }
            return   ResultData<Mat>.Accept(TextResource.filter_action_complete,mat);
        }
    }
}
